<?php
    include_once('Configs/database.php');
    class NhatKiChiTiet extends database{
        private $malophp;
        private $tuan;
        private $thu;
        private $ngay;
        private $sotiet;
        //private $hinhthucday;
        private $noidung;
        private $sosvhiendien;
        private $xacnhancuasv;
        private $maso;
        public function setMaLopHP($malophp){
            $this->malophp = $malophp;
        }
        public function getMaLopHP(){
            return $this->malophp;
        }
        
        public function setTuan($tuan){
            $this->tuan = $tuan;
        }
        public function getTuan(){
            return $this->tuan;
        }
        
        public function setThu($thu){
            $this->thu = $thu;
        }
        public function getThu(){
            return $this->thu;
        }
        public function setNgay($ngay){
            $this->ngay = $ngay;
        }
        public function getNgay(){
            return $this->ngay;
        }
        
        public function setSoTiet($sotiet){
            $this->sotiet = $sotiet;
        }
        public function getSoTiet(){
            return $this->sotiet;
        }
        /*public function setHinhThucDay($hinhthucday){
            $this->hinhthucday = $hinhthucday;
        }
        public function getHinhThucDay(){
            return $this->hinhthucday;
        }*/
        
        public function setNoiDung($noidung){
            $this->noidung= $noidung;
        }
        public function getNoiDung(){
            return $this->noidung;
        }
        
        public function setSoSVHienDien($sosvhiendien){
            $this->sosvhiendien = $sosvhiendien;
        }
        public function getSoSVHienDien(){
            return $this->sosvhiendien;
        }
        
        public function setXacNhanCuaSV($xacnhancuasv){
            $this->xacnhancuasv = $xacnhancuasv;
        }
        public function getXacNhanCuaSV(){
            return $this->xacnhancuasv;
        }
        
        public function setMaSo($maso){
            $this->maso = $maso;
        }
        public function getMaSo(){
            return $this->maso;
        }
        
       
        
        public function ghiXacNhanCuaSV(){
            $query = "update NhatKiChiTiet set xacnhancuasv='".$this->getXacNhanCuaSV()."',maso='".$this->getMaSo()."' where malophp='".$this->getMaLopHP()."' and tuan=".$this->getTuan()." and thu=".$this->getThu()."";
            $this->setQuery($query);
            return $this->executeQuery();
        }
        public function themNhatKiChiTiet(){
            
            $query = "insert into NhatKiChiTiet(malophp,tuan,thu,ngay,sotiet,noidung,sosvhiendien) values('".$this->getMaLopHP()."',";
            $query .= "".$this->getTuan().",".$this->getThu().",str_to_date('".$this->getNgay()."', '%d-%m-%Y'),".$this->getSoTiet().",'".$this->getNoiDung()."',".$this->getSoSVHienDien().")";
            $this->setQuery($query);
            return $this->executeQuery();
        }
        public function suaNhatKiChiTiet(){
            
            $query = "update NhatKiChiTiet set ngay=str_to_date('".$this->getNgay()."', '%d-%m-%Y'),sotiet=".$this->getSoTiet().",noidung='".$this->getNoiDung()."',sosvhiendien=".$this->getSoSVHienDien()." where malophp='".$this->getMaLopHP()."' and tuan=".$this->getTuan()." and thu=".$this->getThu()."";
            $this->setQuery($query);
			//echo $this->getQuery();
            return $this->executeQuery();
        }
        public function xoaNhatKiChiTiet(){
            
             
            $this->setQuery("delete NhatKiChiTiet where malophp='".$this->getMaLopHP()."' and tuan=".$this->getTuan()." and thu=".$this->getThu()." ");
            
            
            return $this->executeQuery();
            
            
        }
        /*public function xoa(){            
             $this->setQuery("delete NhatKiChiTiet where malophp='".$this->getMaLopHP()."' and tuan=".$this->getTuan()." and thu=".$this->getThu()." ");
            $this->setQuery($query);
            //echo $this->getQuery();
            return $this->executeQuery();
            
            
        }*/
         /*public function themNhatKiChiTiet(){
            mysql_query("START TRANSACTION");
            $query = "insert into NhatKiChiTiet(malophp,tuan,thu,ngay,sotiet,hinhthucday,noidung,sosvhiendien) values('".$this->getMaLopHP()."',";
            $query .= "".$this->getTuan().",".$this->getThu().",'".$this->getNgay()."',".$this->getSoTiet().",'".$this->getHinhThucDay()."','".$this->getNoiDung()."',".$this->getSoSVHienDien().")";
            $this->setQuery($query);
            $i = 0;
            if ($this->executeQuery() >0 ){
                $this->setQuery("update NhatKi set tongsotiet = tongsotiet + ".$this->getSoTiet()." where malophp='".$this->getMaLopHP()."'");
                
                $i = $this->executeQuery();
                if ($i > 0){
                    mysql_query("COMMIT"); 
                }
                                                                                                                                                                                                                  
            }
            return $i;
        }
        public function suaNhatKiChiTiet(){
             mysql_query("START TRANSACTION");
            $query = "update NhatKiChiTiet set ngay='".$this->getNgay()."',sotiet=".$this->getSoTiet().",hinhthucday='".$this->getHinhThucDay()."',noidung='".$this->getNoiDung()."',sosvhiendien=".$this->getSoSVHienDien()." where malophp='".$this->getMaLopHP()."' and tuan=".$this->getTuan()." and thu=".$this->getThu()."";
            $i = 0;
            if ($this->executeQuery() >0 ){
                $this->setQuery("update NhatKi set tongsotiet = tongsotiet + ".$this->getSoTiet()." where malophp='".$this->getMaLopHP()."'");
                
                $i = $this->executeQuery();
                if ($i > 0){
                    mysql_query("COMMIT"); 
                }
                                                                                                                                                                                                                  
            }
            return $i;
        }
        
        public function xoaNhatKiChiTiet(){
            mysql_query("START TRANSACTION");
            $this->setQuery("delete NhatKiChiTiet where malophp='".$this->getMaLopHP()."' and tuan=".$this->getTuan()." and thu=".$this->getThu()." ");
            $i = 0;
            if ($this->executeQuery() >0 ){
                $this->setQuery("update NhatKi set tongsotiet = tongsotiet - ".$this->getSoTiet()." where malophp='".$this->getMaLopHP()."'");
                
                $i = $this->executeQuery();
                if ($i > 0){
                    mysql_query("COMMIT"); 
                }
                                                                                                                                                                                                                  
            }
            return $i;
        }
        */
        public function thongTinNhatKiChiTiet(){
            $this->setQuery("select malophp,tuan,thu,date_format(ngay,'%d-%m-%Y') as ngay ,sotiet,hinhthucday,noidung,sosvhiendien,xacnhancuasv from NhatKiChiTiet where malophp='".$this->getMaLopHP()."' and tuan=".$this->getTuan()." and thu=".$this->getThu()."");
            //echo $this->getQuery();
            return $this->fetchAll();
        }
        public function dsNhatKiChiTietLopHP(){
            $this->setQuery("select malophp,tuan,thu, date_format(ngay,'%d-%m-%Y') as ngay ,sotiet,noidung,sosvhiendien,xacnhancuasv,maso from NhatKiChiTiet where malophp='".$this->getMaLopHP()."' order by tuan");
            return $this->fetchAll();
        }
    }
?>